<?php

use backend\widgets\Bar;
use backend\grid\CheckboxColumn;
use backend\grid\ActionColumn;
use backend\grid\GridView;
use yii\helpers\Html;
use backend\models\Photo;
use common\models\Photostatus;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\PhotoSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title                   = 'Photos';
$this->params['breadcrumbs'][] = 'Photos';
?>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox">
            <?= $this->render('/widgets/_ibox-title') ?>
            <div class="ibox-content">
                <!--		发布时使用禁用创建	--><? //= Bar::widget(['template'=>'{refresh}']) ?>
                <!--开发时使用-->
                <?= Bar::widget() ?>
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'filterModel'  => $searchModel,
                    'columns'      => [
                        ['class' => CheckboxColumn::className()],
                        [
                            'attribute'      => 'id',
                            'label'          => 'ID',
                            'contentOptions' => ['style' => 'width:10px!important'],
                        ],
                        [
                            'attribute' => 'authorName',
                            'label'     => '用户',
                            'value'     => 'user.username',
                        ],
                        [
                            'attribute' => 'brife',
                            'value'     => 'shortBrife',
                        ],
                        [
                            'attribute' => 'img',
                            'format'    => 'raw',
                            'label'     => '图片',
                            'value'     => function ($model) {
                                return "<img style='max-width: 200px;max-height: 150px' src='{$model->imgUrl}'>";
                            }
                        ],
                        [
                            'attribute'      => 'status',
                            'value'          => 'status0.name',
                            'filter'         => Photostatus::find()//过滤规则
                                                           ->select(['name', 'id'])
                                                           ->orderBy('id')
                                                           ->indexBy('id')
                                                           ->column(),
                            'contentOptions' => function ($model) {
                                return ($model->status == 3) ? ['style' => 'color:red'] : [];
                            }

                        ],
                        [
                            'class'    => ActionColumn::className(),
                            'buttons'  => [
                                'illegal' => function ($url, $model, $key) {
                                    $options = [
                                        'title'        => Yii::t('yii', '违规'),
                                        'aria-label'   => Yii::t('yii', '违规'),
                                        'data-confirm' => Yii::t('yii', '确认该条内容违规？'),
                                        'data-method'  => 'post',
                                        'data-pjax'    => '3',
                                    ];

                                    return Html::a(
                                        '<span class="btn btn-warning btn-sm glyphicon glyphicon-ban-circle"></span>',
                                        $url,
                                        $options
                                    );
                                }
                            ],
                            'template' => '{view-layer} {update} {delete} {illegal}',
                        ],
                    ],
                ]); ?>
            </div>
        </div>
    </div>
</div>
